/**
 * 
 */
package com.bjtech.web.action.management;

import org.apache.struts2.ServletActionContext;

import com.bjtech.dao.LoginUserInfoDao;
import com.bjtech.domain.LoginUserInfo;
import com.bjtech.domain.User;
import com.bjtech.domain.query.LoginUserInfoQuerySpec;
import com.bjtech.web.action.LyheatBaseAction;
import com.bjtech.web.util.Constants;

/**
 * @author wusg
 *
 */
public class PasswordAction extends LyheatBaseAction {

	private static final long serialVersionUID = 1L;
	private LoginUserInfoDao loginUserInfoDao;
	private LoginUserInfoQuerySpec selectBean;


	public PasswordAction() throws Exception {
		model = new LoginUserInfo();
		selectBean = new LoginUserInfoQuerySpec();
	}
	
	public String execute()
	{
		return edit();
	}
	
	public String edit()
	{
		return "edit";
	}
	public String save()
	{
		LoginUserInfo loginUser = new LoginUserInfo();
		User current_user = (User) ServletActionContext.getRequest().getSession().getAttribute(Constants.MANAGEMENT);
		loginUser = loginUserInfoDao.selectEntity(new LoginUserInfo(), current_user.getUserId());
		if(loginUser!=null && getRequest().getParameter("old_pass_word").equals(loginUser.getPass_word()))
		{
			loginUser.setPass_word(getRequest().getParameter("pass_word"));
			loginUserInfoDao.updateEntity(loginUser);
			super.addActionMessage("密码修改成功！");
		}else{
			super.addFieldError("password", "密码错误，请重新填写！");
		}
		
		return edit();
	}
	
	public void prepare() throws Exception {
	}

	public LoginUserInfoDao getLoginUserInfoDao() {
		return loginUserInfoDao;
	}

	public void setLoginUserInfoDao(LoginUserInfoDao loginUserInfoDao) {
		this.loginUserInfoDao = loginUserInfoDao;
	}

	public LoginUserInfoQuerySpec getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(LoginUserInfoQuerySpec selectBean) {
		this.selectBean = selectBean;
	}

}
